import smtplib
from email.mime.text import MIMEText




mail_host = 'smtp.qq.com'
mail_user = 'cwoner@foxmail.com'
mail_pass = 'paddpwfdonxibjdc'
#邮件发送方邮箱地址
sender = '441847654@qq.com'
#邮件接受方邮箱地址，注意需要[]包裹，这意味着你可以写多个邮件地址群发
receivers = ['cwoner@foxmail.com']


def send_email(title,content):
    print('正在发送报警邮件~~')
    message = MIMEText(content,'plain','utf-8')
    #邮件主题
    message['Subject'] = title
    #发送方信息
    message['From'] = sender
    #接受方信息
    message['To'] = receivers[0]

    #登录并发送邮件
    try:
        smtpObj = smtplib.SMTP()
        #连接到服务器
        smtpObj.connect(mail_host,25)
        #登录到服务器
        smtpObj.login(mail_user,mail_pass)
        #发送
        smtpObj.sendmail(sender,receivers,message.as_string())
        #退出
        smtpObj.quit()
        return True
    except smtplib.SMTPException as e:
        print('error',e) #打印错误
        return False
